package com.lagace.spark.twitter;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import org.jivesoftware.spark.util.ResourceUtils;

public class TwitterPreferenceUI extends JPanel {
	private static final long serialVersionUID = 1L;

	private JTextField username;
	private JPasswordField password;
	private JTextField refresh;

    public TwitterPreferenceUI() {
        setLayout(new GridBagLayout());
        buildUI();
    }

    private void buildUI() {
    	username = new JTextField();
    	refresh = new JTextField();
        password = new JPasswordField();
        password.setEchoChar('*');

        JLabel usernameLabel = new JLabel();
        JLabel passwordLabel = new JLabel();
        JLabel refreshLabel = new JLabel();

        ResourceUtils.resLabel(usernameLabel, username, "Username:");
        ResourceUtils.resLabel(passwordLabel, password, "Password:");
        ResourceUtils.resLabel(refreshLabel, refresh, "Refresh Rate (minutes):");

        add(usernameLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
        add(username, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 100, 0));

        add(passwordLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
        add(password, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 100, 0));

        add(refreshLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
        add(refresh, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 100, 0));

    }
    
    public void setUsername(String username){
    	this.username.setText(username);
    }
    
    public void setPassword(String password){
    	this.password.setText(password);
    }
    
    public String getUsername(){
    	return this.username.getText();
    }
    
    public String getPassword(){
    	StringBuffer sb = new StringBuffer();
    	sb.append(password.getPassword());
    	return sb.toString();
    }

    public void setRefresh(String refresh){
    	this.refresh.setText(refresh);
    }
    
	public String getRefresh() {
		return this.refresh.getText();
	}
}